Skip to content

Conversation

@ashwin-ant
Copy link
Member

@ashwin-ant ashwin-ant commented Jan 9, 2025

  • Makes it so we can run ./bin/cli.js -e FOO=BAR /path/to/server and have it pass the env var to the MCP server.
  • Hides env vars by default in the UI to prevent accidental secret leakage

CleanShot 2025-01-09 at 11 58 10@2x

Motivation and Context

Addresses #94.

How Has This Been Tested?

Verified with command above.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@ashwin-ant ashwin-ant force-pushed the ashwin/envvar branch 3 times, most recently from 936345b to 8a7da27 Compare January 9, 2025 20:19
@ashwin-ant ashwin-ant marked this pull request as ready for review January 9, 2025 20:20
Copy link
Member

@jspahrsummers jspahrsummers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! IMO supporting -- should be a blocker, but the other comments are not essential

Comment on lines 20 to 39
for (let i = 0; i < args.length; i++) {
if (args[i] === "-e" && i + 1 < args.length) {
const [key, value] = args[++i].split("=");
if (key && value) {
envVars[key] = value;
}
} else if (!command) {
command = args[i];
} else {
mcpServerArgs.push(args[i]);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be an npm package that can make this easier, but nbd

bin/cli.js Outdated
let command = null;

for (let i = 0; i < args.length; i++) {
if (args[i] === "-e" && i + 1 < args.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should support -- to end arg parsing, in cases where you might have a server that accepts its own -e option

Copy link
Member

@jerome3o-anthropic jerome3o-anthropic Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

}: SidebarProps) => {
const [theme, setTheme] = useTheme();
const [showEnvVars, setShowEnvVars] = useState(false);
const [shownEnvVars, setShownEnvVars] = useState<Record<string, boolean>>({});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably just use a Set, but up to you

Copy link
Member

@jerome3o-anthropic jerome3o-anthropic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one question - and I also agree that -- would be great to have here, but im happy to take that on as a follow up if you don't have time

newEnv[""] = "";
newEnv[key] = "";
setEnv(newEnv);
setShownEnvVars({});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this hide all previously shown env vars? intential?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Copy link
Member

@jspahrsummers jspahrsummers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gandalf_nod

@ashwin-ant ashwin-ant merged commit 98e6f0e into main Jan 13, 2025
4 checks passed
@ashwin-ant ashwin-ant deleted the ashwin/envvar branch January 13, 2025 20:11
IgnacioC44 referenced this pull request in MCPJam/inspector Jun 21, 2025
allow passing env vars to server from command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants